/**
 * 是否身份证号
 * @param idcardNo
 * @returns {boolean}
 */
export default class ValidateConfirm {
	static isIdCard = idcardNo => {
		var pass = true;
		var len = idcardNo.length, re;
		if (len == 15)
			re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
		else if (len == 18)
			re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d|[Xx])$/);
		else {
			return false;
		}
		var a = idcardNo.match(re);
		if (a != null) {
			let B;
			if (len == 15) {
				var D = new Date('19' + a[3] + '/' + a[4] + '/' + a[5]);
				B = D.getYear() == a[3] && (D.getMonth() + 1) == a[4]
					&& D.getDate() == a[5];
			} else {
				var D = new Date(a[3] + '/' + a[4] + '/' + a[5]);
				B = D.getFullYear() == a[3] && (D.getMonth() + 1) == a[4]
					&& D.getDate() == a[5];
			}
			if (!B) {
				return false;
			}
		}
		return true;
		return pass;

	};


	/**
	 * qq号判断
	 * @param value
	 * @returns {boolean|*}
	 */
	static isQQ = (value) => {
		let pass = true;
		let reg = /^[1-9][0-9]{4,14}$/;
		pass = reg.test(value);
		return pass;
	};

	/**
	 * 手机号码
	 * @param value
	 * @returns {boolean}
	 */
	static isMobile = (value) => {
		let pass = true;

		let length = value.length;
		let reg = /^((1)+\d{10})$/;
		pass = length == 11 && reg.test(value);

		return pass;
	};

	/**
	 * 电话号码
	 * @param value
	 * @returns {boolean|*}
	 */
	static isPhone = (value) => {
		let pass = true;
		let reg = /^((\d{10,11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
		pass = reg.test(value);

		return pass;
	};


	/**
	 *  判断是不是email
	 *
	 * @param value (校验的值)
	 * @returns {boolean|*}
	 */
	static isEmail = (value) => {
		let pass = true;

		pass = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value);

		return pass;
	};

	static isPositiveInteger = (s) => {//是否为正整数 (不包含0)
		let pass = true;
		pass = /^[1-9]+\d*$/.test(s);
		return pass;
	};

	static isNumAndChar = (s) => {
		let pass = true;
		pass = /^[0-9a-zA-Z_]{1,}$/.test(s);
		return pass;
	};
}